
package jard.webshop.nbp;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;

/**
 *
 * @author cjp
 */
@Entity
public class Shipment implements Serializable {
    // Use of @JoinColumn(nullable=false) causes non-deterministic behavior during
    // removal of Users and Orders. So make sure you add an Order to these!
    @OneToOne(mappedBy = "shipment",orphanRemoval=true)
    private Order order;
    @Column(nullable=false)
    private Boolean delivered = false;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date deliveryDate;
    @Column(nullable=false)
    private Float weight = 0f;
    
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    public Shipment() {
    }
    
    public Shipment(Order parent, Float weight) {
        this.order = parent;
        this.weight = weight;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Shipment)) {
            return false;
        }
        Shipment other = (Shipment) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "jard.webshop.nbp.Shipment[ id=" + id + " ]";
    }

    /**
     * @return the order_unit
     */
    public Order getOrder_unit() {
        return order;
    }

    /**
     * @param order_unit the order_unit to set
     */
    public void setOrder_unit(Order order_unit) {
        this.order = order_unit;
    }

    /**
     * @return the delivered
     */
    public Boolean getDelivered() {
        return delivered;
    }

    /**
     * @param delivered the delivered to set
     */
    public void setDelivered(Boolean delivered) {
        this.delivered = delivered;
    }

    /**
     * @return the deliveryDate
     */
    public Date getDeliveryDate() {
        return deliveryDate;
    }

    /**
     * @param deliveryDate the deliveryDate to set
     */
    public void setDeliveryDate(Date deliveryDate) {
        this.deliveryDate = deliveryDate;
    }

    public Float getWeight() {
        return weight;
    }

    public void setWeight(Float weight) {
        this.weight = weight;
    }
    
}
